<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<html:header title="选择进货单">

    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">

    <style type="text/css">
        a{
            color: #01AAED;
            text-decoration: none;
            font-size: 12px;
        }
        a:hover {
            color: #FF5722;
        }
    </style>

    <script>
        jQuery(function () {
            fixTableOperatorButton();
        });

        layui.use(['form', 'table','laydate'], function () {
            let $ = layui.jquery,
                form = layui.form,
                table = layui.table,
                util = layui.util;

            renderTable();

            form.on('submit(search)', function (data) {
                let json = data.field;
                table.reload('table',{where: json,page: {curr: 1}});
                return false;
            });

            table.on('tool(table)', function (obj) {
                let data = obj.data;
                if (obj.event === 'selectOk') {
                    window.parent.getSelectInGoods(data);
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                }
            });

        });

        function renderTable() {
            $("#searchForm")[0].reset();
            layui.table.render({
                id:'table',
                elem: '#table',
                url: "${baseUrl}inGoods/inGoods/getListForSelect.action",
                totalRow:true,
                where : {
                    time:(new Date()).valueOf()
                },
                cols: [[
                    {width:70,title:"序号",templet:function (d) {
                        if (d.refund == 1) {
                            return "<span class='layui-badge layui-bg-orange' style='margin-left: -15px;'>部分退货</span>";
                        } else if (d.refund == 2) {
                            return "<span class='layui-badge layui-bg-orange' style='margin-left: -15px;'>全部退货</span>";
                        } else if (d.close) {
                            return "<span class='layui-badge layui-bg-gray'>作废</span>";
                        } else {
                            return d.LAY_INDEX;
                        }
                    }},
                    {width: 100, title: '业务日期',style:"font-size:12px;",templet: function (d) {
                            return GMTToDate(d.date);
                        }},
                    {field: 'no', width: 130, title: '单据编号',style:"font-size:12px;"},
                    {width: 120, title: '供应商',style:"font-size:12px;", templet: function (d) {
                            return d.provider == null ? "" :d.provider.name;
                        }},
                    // {field:'number', width: 70, title: '进货数量',style:"font-size:12px;", templet: function(d){
                    //         return genGoodsNumber(d.inGoodsGoodsVoList);
                    //     }},
                    {field:'totalAmt',width: 90, title: '应付金额',style:"font-size:12px;",templet: function (d) {
                        return getPrice(d.totalAmt);
                    }},
                    {field:'realAmt',width: 90, title: '已付金额',style:"font-size:12px;",templet: function (d) {
                        let realAmt = getPrice(d.realAmt);
                        if (parseFloat(d.realAmt) < parseFloat(d.totalAmt)){
                            return '<span style="color: #FF5722;">'+realAmt+'</span>';
                        } else {
                            return realAmt;
                        }
                    }},
                    {width: 120, title: '门店',style:"font-size:12px;", templet: function (d) {
                            return d.houseVo == null ? "" :d.houseVo.store.name;
                        }},
                    {width: 120, title: '入库仓库',style:"font-size:12px;", templet: function (d) {
                            return d.houseVo == null ? "" :d.houseVo.name;
                        }},
                    {minWidth: 150, title: '进货商品',style:"font-size:12px;", templet: function(d){
                            return genGoodsAndPacket(d.inGoodsGoodsVoList);
                        }},
                    {title: '操作', minWidth: 70, fixed:'right', templet: '#operBar'},
                ]],
                limit: 10,
                page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                    layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                    //,curr: 5 //设定初始在第 5 页
                    ,groups: 5 //只显示 5 个连续页码
                    ,first: false //不显示首页
                    ,last: false //不显示尾页
                },
                done: function(res, curr, count){
                }
            });

        }
    </script>

</html:header>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="table-tool-div">
            <form class="layui-form layui-form-pane" action="" id="searchForm">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">其他信息</label>
                        <div class="layui-input-inline">
                            <input type="text" id="search" name="search" placeholder="编号、供应商、商品、备注" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <a class="layui-btn" lay-submit="" lay-filter="search" id="btn-search"><i class="layui-icon layui-icon-search"></i></a>
                    </div>
                </div>

            </form>
        </div>
        <hr/>

        <table class="layui-hide" id="table" lay-filter="table" lay-size="sm"></table>

        <script type="text/html" id="operBar">
            <a class="layui-btn layui-btn-xs table-operator" lay-event="selectOk">选择</a>
        </script>
    </div>
</div>
</body>
<html:loading/>
</html>